package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dao.CategroryDao;
import com.vo.Category;

public class ProductClassServlet_s extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		CategroryDao dao = new CategroryDao();
		List<Category> list = null;
		int page = 0;
		int pageCount = 10;
		int count = 0;
		if(request.getParameter("page") ==null || Integer.parseInt(request.getParameter("page"))< 1){
			page = 1;
		}else{
			page = Integer.parseInt(request.getParameter("page"));
		}
		try {
			 list =  dao.getProduct(page, pageCount);
			 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			if( dao.getCount()%pageCount >= 1){
			
				count = dao.getCount()/pageCount+1;
			}else{
				count = dao.getCount()/pageCount;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HttpSession session = request.getSession();
		if(page == count){
			session.setAttribute("page", page-1);
		}else{
			session.setAttribute("page", page);
		}
		
		session.setAttribute("allData", list);
		session.setAttribute("count", count);
		request.getRequestDispatcher("manage/productClass_s.jsp").forward(request, response);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
